<template>
    <div>
        <div>
            <el-form :inline="true" label-width="100" :model="formInline"  class="demo-form-inline">
                <el-form-item label="条码">
                    <el-input class="input-width" v-model="formInline.barcode" size="mini" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="图号：">
                    <el-input class="input-width" v-model="formInline.itemCode" size="mini" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="成品型号：">
                    <el-input class="input-width" v-model="formInline.mProductNumber" size="mini" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="质量编号：">
                    <el-input class="input-width" v-model="formInline.qualityCode" size="mini" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="交接状态：">
                    <el-select v-model="formInline.deliveryStatus" size="mini">
                        <el-option
                            v-for="item in options1"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        >
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="交接单号：">
                    <el-input class="input-width" v-model="formInline.deliveryPlanCode" size="mini" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="移交单位简码：">
                    <el-input class="input-width" v-model="formInline.deliveryOrgCode" size="mini" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="接收单位简码：">
                    <el-input class="input-width" v-model="formInline.receiveOrgCode" size="mini" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="机型：">
                    <el-input class="input-width" v-model="formInline.productCode" size="mini" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="批次：">
                    <el-input class="input-width" v-model="formInline.batchNo" size="mini" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="起始架次：">
                    <el-input class="input-width" v-model="formInline.startLotNo" size="mini" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="截止架次：">
                    <el-input class="input-width" v-model="formInline.endLotNo" size="mini" placeholder="请输入"></el-input>
                </el-form-item>
                
                <el-form-item label="配送时间">
                    <el-date-picker style="width:140px" value-format="yyyy-MM-dd" v-model="formInline.startTime" size="mini" type="date" placeholder="开始日期"></el-date-picker>到
                    <el-date-picker style="width:140px" value-format="yyyy-MM-dd" v-model="formInline.endTime" size="mini" type="date" placeholder="结束日期"></el-date-picker>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" size="mini" @click="doQuery">查询</el-button>
                    <el-button type="primary" size="mini" @click="doReset">重置</el-button>
                    <el-button type="primary" size="mini" @click="updateWmsDelivery">修改交接单</el-button>
                    <el-button type="primary" size="mini" @click="upDelivereyStatus">修改交接单状态</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="im-hq-topTable">
            <el-table  ref="multipleTable"  size="mini"  :data="tableData"  style="width: 100%" @selection-change="handleSelectionChange"  height="450" >
                <el-table-column type="selection" width="40"> </el-table-column>
                <el-table-column prop="ROW_ID" label="序号" width="50" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="deliveryStatus" label="交接状态" width="70" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="barcode" label="条码" width="150" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="mProductNumber" label="成品型号" width="120" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="itemCode" label="图号" width="160" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="qualityCode" label="质量编号" width="130" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="itemName" label="物料名称" width="130" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="deliveryPlanCode" label="交接单号" width="160" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="deliveryQty" label="移交数量" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="storageQty" label="接收数量" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="deliveryEmpCode" label="移交人" width="70" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="deliveryDate" label="移交时间" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="productCode" label="机型" width="70" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="batchNo" label="批次" width="50" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="startLotNo" label="起始架次" width="70" :show-overflow-tooltip="true" > </el-table-column>
                <el-table-column prop="endLotNo" label="截止架次" width="70" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="mesCheckQualiticationId" width="160" label="合格证号" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="xProductCode" label="限用机型" width="70" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="xLimitBatchNo" label="限用批次" width="70" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="xLimitLotNo" label="限用架次" width="70" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="wmsDeliveryPlanId" label="交接单ID" width="70" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="deliveryStatusCode" label="交接单状态" width="0" :show-overflow-tooltip="true"> </el-table-column>
            </el-table>
            <!-- 分页 -->
            <el-pagination  @size-change="handleSizeChange" @current-change="handleCurrentChange"  :current-page="page.currentPage"
                :page-sizes="[10,20,50,100]" :page-size="page.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="page.total">
            </el-pagination>
        </div>
        <!--修改交接单-->
        <div>
            <el-dialog title="交接单" :visible.sync="dialog.dialogFormVisible" label-width="100">
                <el-form :model="form" :inline="true" size="mini">
                    <el-form-item label="条码">
                        <el-input v-model="form.barcode" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="合格证号">
                        <el-input v-model="form.mesCheckQualiticationId" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="机型">
                        <el-input v-model="form.productCode" autocomplete="off" ></el-input>
                    </el-form-item>
                    <el-form-item label="开始架次">
                        <el-input v-model="form.startLotNo" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="结束架次">
                        <el-input v-model="form.endLotNo" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="质量编号">
                        <el-input v-model="form.qualityCode" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="标准件计划图号">
                        <el-input v-model="form.applyItemCode" autocomplete="off"></el-input>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button size="mini" @click="dialog.dialogFormVisible = false">取 消</el-button>
                    <el-button size="mini" type="primary" @click="saveData">确 定</el-button>
                </div>
            </el-dialog>
        </div>
        <div>
            <el-dialog title="交接单状态" :visible.sync="dialog2.dialogFormVisible" label-width="100">
                <el-form :model="deliveryForm" :inline="true" size="mini">
                    <el-form-item label="交接单号">
                        <el-input v-model="deliveryForm.deliveryPlanCode" autocomplete="off" ></el-input>
                    </el-form-item>
                    <el-form-item label="交接单状态">
                        <el-input v-model="deliveryForm.deliveryStatusCode" autocomplete="off"></el-input>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button size="mini" @click="dialog2.dialogFormVisible = false">取 消</el-button>
                    <el-button size="mini" type="primary" @click="saveDevlieryStatus">确 定</el-button>
                </div>
            </el-dialog>
        </div>
    </div>
  </template>
  <script>
  import request from "@/utils/request.js";
  export default {
    name: "wmsDeliveryTicketQuery",
    data() {
      return {
        formInline:{
            barcode:"",
            itemCode:"",
            mProductNumber:"",
            qualityCode:"",
            deliveryStatus:"",
            deliveryPlanCode:"",
            deliveryOrgCode:"",
            receiveOrgCode:"",
            productCode:"",
            batchNo:"",
            startLotNo:"",
            endLotNo:"",
            startTime:"",
            endTime:""
        },
        
        options1:[
                {
                    value: "",
                    label: "所有状态",
                },
                {
                    value: "1",
                    label: "未确认",
                },
                {
                    value: "2",
                    label: "已移交",
                },
                {
                    value: "3",
                    label: "待入库",
                },
                {
                    value: "6",
                    label: "已入库",
                },
                {
                    value: "7",
                    label: "已退回",
                },
            ],
        page:{
            total:1,
            pageSize:50,
            currentPage:1
        },
        tableData:[],
        selectData:[],
        dialog:{
            dialogFormVisible:false
        },
        form:{},
        dialog2:{
            dialogFormVisible:false
        },
        deliveryForm:{}
      };
    },
    methods:{
        handleSelectionChange(val){
            this.selectData = val;
        },
        handleSizeChange(val){
            this.page.pageSize = val;
        },
        handleCurrentChange(val){
            this.page.currentPage = val;
            this.$options.methods.doQuery.bind(this)();
        },
        doQuery(){  
            var that = this;
            var page = {"page":this.page.currentPage,"rows":this.page.pageSize};
            request.post("/DeliveryPlanQuery/ParamsByDeliveryQuery",{"pageParameter":page,"searchParams":this.formInline}).then((res)=>{
                console.log(res);
                // that.tableData = res.data.list;
                that.tableData = res.data.responseBody.result;
                that.page.total = res.data.responseBody.pageParameter.totalCount;
            });
        },
        doReset(){
            Object.assign(this.formInline,this.$options.data().formInline);
        },
        updateWmsDelivery(){
            console.log("selectData",this.selectData);
            if(this.selectData.length!=1){
                this.$Alert({title: "错误", message: '请选择一条数据',type: "error"});
                return;
            }
            this.dialog.dialogFormVisible = true;
            this.form = this.selectData[0];
        },
        saveData(){
            var message = "";
            var A = Math.ceil(Math.random()*100);
            var B = Math.ceil(Math.random()*10);
            var C = Math.ceil(Math.random()*100);
            var D = Math.ceil(Math.random()*100);
            message = "请将 "+A+"/"+B+"+"+C+"%"+D+" 计算的结果输入到输入框中!";
            console.log(Math.floor(A/B)+"============"+C%D);
            var result = Math.floor(A/B)+C%D;
            this.$prompt(message,"提示",{ 
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'}
            ).then(({value})=>{
                console.log("value",value);
                console.log("result",result);
                if(result != value){
                    this.$Alert({type:"error",title:"成功",message:"计算的结果不对"});
                    return;
                }
                request.post("/DeliveryPlanQuery/updateWmsDelivery",this.form).then((res)=>{
                    console.log("res",res);
                    if(res.data.retCode=="200"){
                        this.$Alert({title: "成功", message: '操作成功',type: "success"});
                    }else{
                        this.$Alert({title: "错误", message: '操作失败',type: "error"});
                    }
                    this.dialog.dialogFormVisible = false;
                    this.$options.methods.doQuery.bind(this)();
                });
            });
            
        },
        upDelivereyStatus(){
            console.log("selectData",this.selectData);
            if(this.selectData.length!=1){
                this.$Alert({title: "错误", message: '请选择一条数据',type: "error"});
                return;
            }
            this.dialog2.dialogFormVisible = true;
            this.deliveryForm = this.selectData[0];
        },
        saveDevlieryStatus(){//修改交接单状态
            var message = "";
            var A = Math.ceil(Math.random()*100);
            var B = Math.ceil(Math.random()*10);
            var C = Math.ceil(Math.random()*100);
            var D = Math.ceil(Math.random()*100);
            message = "请将 "+A+"/"+B+"+"+C+"%"+D+" 计算的结果输入到输入框中!";
            console.log(Math.floor(A/B)+"============"+C%D);
            var result = Math.floor(A/B)+C%D;
            this.$prompt(message,"提示",{ 
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'}
            ).then(({value})=>{
                console.log("value",value);
                console.log("result",result);
                if(result != value){
                    this.$Alert({type:"error",title:"成功",message:"计算的结果不对"});
                    return;
                }
                //updateWmsDelivery
                request.post("/DeliveryPlanQuery/updateWmsDeliveryStatus",this.deliveryForm).then((res)=>{
                    console.log("res",res);
                    if(res.data.retCode=="200"){
                        this.$Alert({title: "成功", message: '操作成功',type: "success"});
                    }else{
                        this.$Alert({title: "错误", message: '操作失败',type: "error"});
                    }
                    this.dialog2.dialogFormVisible = false;
                    this.$options.methods.doQuery.bind(this)();
                });
            });
        }
    }
  };
  </script>